from app.extensions import db
from datetime import datetime
# 发表的内容
class Posts(db.Model):
    __tablename__ = 'posts'
    id = db.Column(db.Integer,primary_key=True)
    rid = db.Column(db.Integer,index=True,default=0)
    # 指明外键关联
    uid = db.Column(db.Integer,db.ForeignKey('users.id'))
    content = db.Column(db.Text)
    timestamp = db.Column(db.DateTime,default=datetime.utcnow)
    pingtexts= db.relationship('PingTexts',backref='post',lazy='dynamic')
# 评论内容表
class PingTexts(db.Model):
    __tablename__ = 'pingtexts'
    id = db.Column(db.Integer, primary_key=True)
    pcontent = db.Column(db.Text)
    puser = db.Column(db.String(32))
    p_pid = db.Column(db.Integer,db.ForeignKey('posts.id'))
    ptime = db.Column(db.DateTime,default=datetime.utcnow)
    huitexts= db.relationship('HuiTexts',backref='pingtext',lazy='dynamic')
# 回复的内容
class HuiTexts(db.Model):
    __tablename__ = 'huitexts'
    id = db.Column(db.Integer, primary_key=True)
    hcontent = db.Column(db.Text)
    huser = db.Column(db.String(32))
    h_pid = db.Column(db.Integer,db.ForeignKey('pingtexts.id'))
    htime = db.Column(db.DateTime,default=datetime.utcnow)



class RePosts(db.Model):
    __tablename__='reposts'
    id = db.Column(db.Integer, primary_key=True) #id
    bid = db.Column(db.Integer, index=True, default=0)  #被评论人id
    rid = db.Column(db.Integer, index=True, default=0)  #评论人id
    content = db.Column(db.Text)                         #评论内容
    rtime = db.Column(db.DateTime, default=datetime.utcnow)  #评论时间